/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edi.controller;

import edi.api.Employee;
import edi.api.response.EmployeeListResponse;
import edi.dao.UserDao;
import edi.entities.UserEntity;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("employee")
public class EmployeeController {
    
    @Autowired
    private UserDao userDao;
    
    
    @ResponseBody
    @RequestMapping(value = "/getEmployees", method = RequestMethod.GET)
    public EmployeeListResponse getEmployees() {
        EmployeeListResponse response = new EmployeeListResponse();
        
        List<UserEntity> employeeEntities = userDao.findAll();
        List<Employee> employeesList = new ArrayList<Employee>(employeeEntities.size());
        
        for(UserEntity userEntity : employeeEntities){
            Employee employee = new Employee();
            employee.setEmployeeID(userEntity.getUsrId());
            employee.setEmployeeName(userEntity.getUsrFirstName());
            employee.setEmployeeSurname(userEntity.getUsrLastName());
//            employee.setDepartmentID(userEntity.getUserDeps().get(0).getUdeDepartment().getDepId());
            //potrzebne login i passwrod?
            employee.setEmployeeLogin(userEntity.getUsrLogin());
            String status = userEntity.getUsrStatus();
            employee.setEmployeeStatus(status);
            if(status != null && status.equals("1")){
                employeesList.add(employee);
            }
            
        }
        response.setEmployees(employeesList);
        
        return response;
    }
}
